001    /*
002     * Copyright (c) 2005 Stephen J. McConnell
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.component;
020    
021    import net.dpml.lang.Enum;
022    
023    /**
024     * Policy enummeration for the declaration of activation semantics.
025     *
026     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
027     * @version 1.0.1
028     */
029    public final class ActivationPolicy extends Enum
030    {
031        static final long serialVersionUID = 1L;
032    
033       /**
034        * System managed activation policy.
035        */
036        public static final ActivationPolicy SYSTEM = new ActivationPolicy( "system" );
037    
038       /**
039        * Activation on startup enabled.
040        */
041        public static final ActivationPolicy STARTUP = new ActivationPolicy( "startup" );
042    
043       /**
044        * Activation on startup disabled.
045        */
046        public static final ActivationPolicy DEMAND = new ActivationPolicy( "demand" );
047    
048       /**
049        * Array of static activation policy enumeration values.
050        */
051        private static final ActivationPolicy[] ENUM_VALUES = 
052          new ActivationPolicy[]{SYSTEM, STARTUP, DEMAND};
053    
054       /**
055        * Returns an array of activation enum values.
056        * @return the activation policies array
057        */
058        public static ActivationPolicy[] values()
059        {
060            return ENUM_VALUES;
061        }
062            
063       /**
064        * Parse a string value and return the activation policy.
065        * @param value the activation policy name
066        * @return the activation policy
067        */
068        public static ActivationPolicy parse( String value )
069        {
070            if( value.equalsIgnoreCase( "system" ) )
071            {
072                return SYSTEM;
073            }
074            else if( value.equalsIgnoreCase( "startup" ) )
075            {
076                return STARTUP;
077            }
078            else if( value.equalsIgnoreCase( "demand" ) )
079            {
080                return DEMAND;
081            }
082            else
083            {
084                final String error =
085                  "Unrecognized activation policy argument [" 
086                  + value 
087                  + "]";
088                  throw new IllegalArgumentException( error );
089            }
090        }
091        
092       /**
093        * Internal constructor.
094        * @param label the enumeration label.
095        */
096        private ActivationPolicy( String label )
097        {
098            super( label );
099        }
100    }